<template>
	<view class="main">
		<u-navbar :is-back="false" :background="background" :border-bottom="false" height="64">
			<view class="content">
				<view class="head" @click="router()">
					<image src="../../../static/images/serch.png" mode=""></image>
					<text> </text>
				</view>
			</view>
		</u-navbar>
		<view class="all">
			<view class="banner">
				<u-swiper :list="bannerlist" border-radius="0" name="img" height="300"></u-swiper>
			</view>
			<view class="bannerborder">

			</view>
			<view class="operate">
				<view class="class" @click="goclass()">
					<image src="../../../static/images/classcenter.png" mode=""></image>
					<text>课程中心</text>
				</view>
				<view class="class" @click="go('../audition/audition')">
					<image src="../../../static/images/audition.png" mode=""></image>
					<text>免费试听</text>
				</view>
			</view>
			<view class="contentit">
				优选好课
			</view>
			<scroll-view scroll-y="true" >
				<view class="classes" v-for="(item,index) in classlist" :key="index"
					@click="item.type==1?go('../../classes/details/details',item.id,item):go('../../classes/privilege/privilege',item.id,item)">
					<view class="one_of">
						<view class="class_l">
							<image :src="item.cover" mode=""></image>
						</view>
						<view class="class_r">
							<view class="topic">{{item.title}}</view>
							<text class="name">讲师：{{item.lecturer}}</text>
						</view>
					</view>
					<view class="one_bottom">
						<text class="bot_l">{{item.count}}节课</text>
						<text class="bot_r">立即学习</text>
					</view>
				</view>
			</scroll-view>

		</view>

	</view>
</template>
<script>
	export default {
		data() {
			return {
				background: {
					backgroundColor: '#11D1A8',
				},
				bannerlist: [

				],
				autoplay: true,
				interval: 2000,
				duration: 500,
				level: '',
				classlist: []
			}
		},
		onShow() {
			this.getlevel()
			this.getbanner()
			this.getcalss()
		},
		onLoad(options) {

		},
		methods: {
			//获取课程
			getcalss() {
				global.$http.request({
					url: '/api/home/course',
					data: {
						token: uni.getStorageSync('token')
					}
				}).then(res => {
					if (res.data.code == 200) {
						// console.log(res.data.data);
						this.classlist = res.data.data.data
						// console.log(this.classlist);
					}
				})
			},
			//权限
			getlevel() {
				global.$http.request({
					url: '/api/User/info',
					data: {
						token: uni.getStorageSync('token')
					}
				}).then(res => {
					if (res.data.code == 200) {
						// console.log(res);
						this.level = res.data.data
					}
				})
			},
			// banner图
			getbanner() {
				global.$http.request({
					url: '/api/home/banner', 
				}).then(res => {
					if (res.data.code == 200) {
						this.bannerlist = res.data.data
					}
				})
			},
			goclass() {
				uni.reLaunch({
					url: '../../classes/class/class'
				})
			},
			go(path, id, info) {
				uni.navigateTo({
					url: path + '?id=' + id + '&info=' + encodeURIComponent(JSON.stringify(info))
				})
			},
			router() {
				uni.navigateTo({
					url: '../serch/serch',
					animationType: 'zoom-fade-out',
					animationDuration: 200
				})
			}

		}
	}
</script>

<style lang="scss">
	page {
		width: 750rpx;
		height: 100vh;
		font-family: PingFang SC;
		background-color: #F7F7F7;
		// overflow: hidden;

		.main {
			padding-bottom: 80rpx;

			.content {
				width: 750rpx;
				display: flex;
				flex-direction: column;
				align-items: center;

				image {
					width: 38rpx;
					height: 38rpx;
				}

				.head {
					padding: 0rpx 10rpx;
					background: #FFFFFF;
					border-radius: 10rpx;
					display: flex;
					align-items: center;

					image {
						width: 38rpx;
						height: 38rpx;
					}

					text {
						display: block;
						width: 531rpx;
						height: 56rpx;
						line-height: 56rpx;
						font-size: 28rpx;
						font-family: Source Han Sans CN;
						font-weight: 400;
						color: #AFB1B2;
					}
				}
			}

			.all {
				.banner {}

				.bannerborder {
					width: 750rpx;
					height: 25rpx;
					border-radius: 0 0 50% 50%;
					background-color: #11D2A9;
				}

				.operate {
					position: relative;
					top: -25rpx;
					width: 710rpx;
					margin: 0 auto;
					height: 194rpx;
					background: #FFFFFF;
					border-radius: 10rpx;
					display: flex;
					justify-content: space-around;
					align-items: center;

					.class {
						display: flex;
						flex-direction: column;
						align-items: center;

						image {
							width: 114rpx;
							height: 114rpx;
						}

						text {
							font-size: 26rpx;
							font-family: Source Han Sans CN;
							font-weight: 400;
							color: #414546;
						}
					}
				}

				.contentit {
					padding: 19rpx 0 29rpx 21rpx;
					font-size: 34rpx;
					font-family: Source Han Sans CN;
					font-weight: bold;
					color: #414546;
				}

				.classes {
					padding: 30rpx 30rpx 0rpx 30rpx;
					background-color: #fff;
					margin-bottom: 10rpx;

					.one_of {
						display: flex;
						align-items: center;
						padding-bottom: 26rpx;
						border-bottom: 2rpx solid #F5F7F9;

						.class_l {
							padding-right: 30rpx;

							image {
								width: 230rpx;
								height: 127rpx;
								border-radius: 6rpx;
							}
						}

						.class_r {
							.topic {
								font-size: 27rpx;
								font-family: Source Han Sans CN;
								font-weight: 400;
								color: #353535;
								margin-bottom: 17rpx;
							}

							.name {
								background: #FFFFFF;
								border: 2rpx solid #FF5850;
								border-radius: 6rpx;
								height: 36rpx;
								padding: 4rpx 17rpx;
								font-size: 22rpx;
								font-family: Source Han Sans CN;
								font-weight: 400;
								color: #FF5850;
							}
						}
					}

					.one_bottom {
						display: flex;
						justify-content: space-between;
						align-items: center;
						padding: 20rpx 0;

						.bot_l {
							font-size: 26rpx;
							font-family: Source Han Sans CN;
							font-weight: 400;
							color: #7B7B7B;
						}

						.bot_r {
							font-size: 30rpx;
							font-family: Source Han Sans CN;
							font-weight: 400;
							color: #09B06B;
						}
					}
				}
			}
		}
	}
</style>
